﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using predic.Web.Host.Services;
using System.ComponentModel;

namespace predic.Web2.Views
{
    public partial class EditStudy : ChildWindow, INotifyPropertyChanged
    {
        private PredicContext ctx = new PredicContext();

        public predic.Web.Host.Model.ViewStudy SelectedViewStudy { get; set; }

        public EditStudy()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(EditStudy_Loaded);
        }

        void EditStudy_Loaded(object sender, RoutedEventArgs e)
        {
            this.BusyIndicator.IsBusy = true;
            this.DataContext = this;
            this.ctx.Load(ctx.GetStudyViewByDetailIDQuery(SelectedViewStudy.IDDetail),
                (load_operation) =>
                {
                    SelectedViewStudy = load_operation.Entities.ElementAt(0);
                    NotifyProperty("SelectedViewStudy");

                    ProcessStudy();
                    this.BusyIndicator.IsBusy = false;

                }, null);
        }

        private void ProcessStudy()
        {

        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            SaveStudy();

        }

        private void SaveStudy()
        {
            ctx.SubmitChanges(
                (submit_operation) =>
                {
                    this.DialogResult = true;

                }, null);
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyProperty(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}

